matrix = [["1", "0", "1", "0", "0"],
          ["1", "0", "1", "1", "1"],
          ["1", "1", "1", "1", "1"],
          ["1", "0", "0", "1", "0"]]

max_r = len(matrix)
max_c = len(matrix[0])

dp = [[0] * max_c for _ in range(max_r)]
res = 0

for i in range(max_r):
    for j in range(max_c):
        if matrix[i][j] == "1":
            if i == 0 or j == 0:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) + 1

        res = max(res, dp[i][j])

print(res * res)
